package com.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;

/**
 * Created by buguniao on 15/12/7.
 */
public class CharClient {
    public static void main(String[] args) throws IOException {
        SocketChannel client = SocketChannel.open();
        SocketAddress address = new InetSocketAddress("localhost",8080);
        client.connect(address);

        WritableByteChannel out = Channels.newChannel(System.out);
        ByteBuffer bf = ByteBuffer.allocate(74);
        while(client.read(bf)!=-1){
            bf.flip();
            out.write(bf);
            bf.clear();
        }
    }
}
